package cinemapi.telas;

import cinemapi.telas.TelaRelatorio;
import cinemapi.telas.TelaPrincipalCadastro;
import cinemapi.telas.TelaPrincipalVendas;
import java.awt.Dimension;

public class TelaPrincipal extends javax.swing.JFrame {

    public TelaPrincipal() {
        initComponents();
        setExtendedState(MAXIMIZED_BOTH);//faz a janela maximizar
    }
    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        painelDesktop = new javax.swing.JDesktopPane();
        BtnImagem = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        btnArquivo = new javax.swing.JMenu();
        MenuItemVenda = new javax.swing.JMenuItem();
        MenuItemCadastro = new javax.swing.JMenuItem();
        MenuItemRelatorio = new javax.swing.JMenuItem();
        MenuItemSair = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        painelDesktop.setBackground(new java.awt.Color(255, 255, 255));
        painelDesktop.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        BtnImagem.setText("jButton2");
        BtnImagem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnImagemActionPerformed(evt);
            }
        });
        BtnImagem.setBounds(500, 200, 280, 240);
        painelDesktop.add(BtnImagem, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnArquivo.setText("Arquivo");

        MenuItemVenda.setText("Venda");
        MenuItemVenda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuItemVendaActionPerformed(evt);
            }
        });
        btnArquivo.add(MenuItemVenda);

        MenuItemCadastro.setText("Cadastro");
        MenuItemCadastro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuItemCadastroActionPerformed(evt);
            }
        });
        btnArquivo.add(MenuItemCadastro);

        MenuItemRelatorio.setText("Relatórios");
        MenuItemRelatorio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuItemRelatorioActionPerformed(evt);
            }
        });
        btnArquivo.add(MenuItemRelatorio);

        MenuItemSair.setText("Sair");
        MenuItemSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuItemSairActionPerformed(evt);
            }
        });
        btnArquivo.add(MenuItemSair);

        jMenuBar1.add(btnArquivo);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(painelDesktop, javax.swing.GroupLayout.DEFAULT_SIZE, 783, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(painelDesktop, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TelaPrincipal().setVisible(true);
            }
        });
    }
    
    private void MenuItemSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuItemSairActionPerformed
       this.dispose();//Função sair 
    }//GEN-LAST:event_MenuItemSairActionPerformed


 
    public static void centralizar(javax.swing.JInternalFrame fr){//centralizar
      Dimension d = fr.getDesktopPane().getSize();
      fr.setLocation((d.width - fr.getSize().width) / 2, (d.height - fr.getSize().height) / 2);
   }
    

    private void MenuItemCadastroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuItemCadastroActionPerformed
       TelaPrincipalCadastro tela2 = new TelaPrincipalCadastro();//criando objeto da TelaPrincipalCadastro
       painelDesktop.add(tela2);//adicionando tela no desktop
      //painelDesktop.getDesktopManager().activateFrame(tela2);//Manda janela abrir
      //tela2.setSize(painelDesktop.getSize());//copiando tamanho do painel principal
       tela2.setVisible(true);
       this.centralizar(tela2);
       
    }//GEN-LAST:event_MenuItemCadastroActionPerformed

    private void MenuItemRelatorioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuItemRelatorioActionPerformed
       TelaRelatorio tela3 = new TelaRelatorio();//criando objeto da TelaPrincipalCadastro
       painelDesktop.add(tela3);//adicionando tela no desktop
      //painelDesktop.getDesktopManager().activateFrame(tela2);//Manda janela abrir
      //tela2.setSize(painelDesktop.getSize());//copiando tamanho do painel principal
       tela3.setVisible(true);
       this.centralizar(tela3);
    }//GEN-LAST:event_MenuItemRelatorioActionPerformed

    private void BtnImagemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnImagemActionPerformed
        //this.BtnImagem.setLocation(500, 100);
}//GEN-LAST:event_BtnImagemActionPerformed

    private void MenuItemVendaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuItemVendaActionPerformed
       cinemapi.telas.TelaPrincipalVendas tela1 = new cinemapi.telas.TelaPrincipalVendas();//criando objeto da TelaPrincipalVendas
       painelDesktop.add(tela1);//adicionando tela no desktop
       tela1.setVisible(true);
       this.centralizar(tela1);
    }//GEN-LAST:event_MenuItemVendaActionPerformed



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BtnImagem;
    private javax.swing.JMenuItem MenuItemCadastro;
    private javax.swing.JMenuItem MenuItemRelatorio;
    private javax.swing.JMenuItem MenuItemSair;
    private javax.swing.JMenuItem MenuItemVenda;
    private javax.swing.JMenu btnArquivo;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JDesktopPane painelDesktop;
    // End of variables declaration//GEN-END:variables

}
